clear; 
clc;
close all;
% 读取图像
psf_image = imread('psf_estimate.tif');
fig_image = imread('Fig01.tif');

% 转换为灰度图像
psf_image = psf_image(:,:,1);
fig_image = fig_image(:,:,1);


% 确保是二维矩阵
psf_image = squeeze(psf_image);
fig_image = squeeze(fig_image);

% 转换为双精度
psf_image = im2double(psf_image);
fig_image = im2double(fig_image);

% PSF 预处理
threshold = 0.5; % 阈值
binary_psf = psf_image > threshold;
psf = binary_psf ./ sum(binary_psf, "all"); % 归一化

% 调用自定义 Lucy-Richardson 函数
num_iterations = 8; % 迭代次数
deblurred_image = lucy_richardson(fig_image, psf, num_iterations);

% 显示结果
figure;
subplot(1, 2, 1);
imshow(fig_image, []);
title('原始模糊图像');

subplot(1, 2, 2);
imshow(deblurred_image, []);
title('去模糊图像');

% 保存结果
imwrite(deblurred_image, 'deblurred_Fig01.tif');
